package com.yunbiao.ybbusstopplate.utils;

import android.app.Activity;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ActivityUtils {
    private static List<Activity> atyList=new ArrayList<>();
    private static ActivityUtils activityUtils;
    private ActivityUtils(){}
    public static ActivityUtils getInstance(){
        if (activityUtils==null){
            activityUtils=new ActivityUtils();
        }
        return activityUtils;
    }



    public void addAty(Activity aty){
        if (atyList.contains(aty)){
            return;
        }
        atyList.add(aty);
    }

    public void removeAty(Activity aty){
        if (atyList.contains(aty)){
            atyList.remove(aty);
        }
    }

    public void finishAll(){
        finishOther(null);
    }

    public void finishOther(Class<? extends Activity> aty){
        for (Iterator<Activity> iterator = atyList.iterator(); iterator.hasNext(); ) {
            Activity activity = iterator.next();
            if (activity.getClass() == aty) {
                continue;
            }
            iterator.remove();
            activity.finish();
        }
    }
}
